package com.xiamaliu.demo.action;

import com.xiamaliu.spring.annotation.GPAutowired;
import com.xiamaliu.spring.annotation.GPController;
import com.xiamaliu.spring.annotation.GPRequestMapping;
import com.xiamaliu.spring.annotation.GPRequestParam;
import com.xiamaliu.demo.service.IDemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@GPController
@GPRequestMapping("/demo")
public class DemoAction {

    @GPAutowired
    private IDemoService demoService;

    private IDemoService demoService2;

    @GPRequestMapping("/query")
    public void query(HttpServletRequest request, HttpServletResponse response,
                      @GPRequestParam("name") String name, @GPRequestParam("id") String id) {
        String result = "My name is " + name + " , id = " + id;
        try {
            response.getWriter().write(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @GPRequestMapping("/add")
    public void add(HttpServletRequest request, HttpServletResponse response,
                    @GPRequestParam("a") String a, @GPRequestParam("b") String b) {
        try {
            response.getWriter().write(a + "+" + b + "=" + (a + b));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
